package nero.yncc.com.createart.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.LinkedHashMap;

import nero.yncc.com.createart.R;
import nero.yncc.com.createart.activity.ActivityUserChange;
import nero.yncc.com.createart.adapter.AdapterUcenter;
import nero.yncc.com.createart.base.BaseFragment;
import nero.yncc.com.createart.base.Constants;
import nero.yncc.com.createart.custom.MyRecyclerView;
import nero.yncc.com.createart.utils.TextUtil;
import nero.yncc.com.createart.utils.UserDataUtil;

/**
 * Created by nero on 17-6-22.
 */

@ContentView(R.layout.fragment_ucenter)
public class FragmentUcenter extends BaseFragment {

    @ViewInject(R.id.rc_ucenter)
    MyRecyclerView rc_ucenter;
    @ViewInject(R.id.tv_name)
    TextView tv_name;
    @ViewInject(R.id.iv_head)
    ImageView iv_head;
    @ViewInject(R.id.tv_tint)
    TextView tv_tint;

    LinkedHashMap<Integer, String> hashMap;
    AdapterUcenter adapterUcenter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = x.view().inject(this, inflater, container);
        initAll();

        return view;
    }

    @Override
    protected void initView() {
        ding();
    }

    @Override
    protected void initData() {
        hashMap = new LinkedHashMap<>();
        hashMap.put(R.mipmap.order, "我的订单");
        hashMap.put(R.mipmap.about, "关于缕墨");
        hashMap.put(R.mipmap.collection, "我的收藏");
        hashMap.put(R.mipmap.contentus, "联系我们");
        hashMap.put(R.mipmap.usermsg, "个人信息");
        hashMap.put(R.mipmap.sitemsg, "站内消息");
        hashMap.put(R.mipmap.address, "收货地址");
        hashMap.put(R.mipmap.setting, "设置");
        hashMap.put(R.mipmap.exitgod, "退货查询");
        adapterUcenter = new AdapterUcenter(getContext(), hashMap);
        rc_ucenter.setAdapter(adapterUcenter);
        GridLayoutManager manager = new GridLayoutManager(getContext(), 3, LinearLayoutManager.VERTICAL, false);
        rc_ucenter.setLayoutManager(manager);
        adapterUcenter.notifyDataSetChanged();

        x.image().bind(iv_head,Constants.IMAGE_HOST+userBean.getHead_pic() , Constants.IMAGEOPTIONS);
        tv_name.setText(TextUtil.getText(userBean.getNickname(),"未设置昵称"));
    }

    @Override
    protected void getHttpData() {
        super.getHttpData();


    }

    @Override
    public void onStart() {
        super.onStart();
        userBean= UserDataUtil.getUserData(getContext());
        x.image().bind(iv_head,Constants.IMAGE_HOST+userBean.getHead_pic() , Constants.IMAGEOPTIONS);
        tv_name.setText(TextUtil.getText(userBean.getNickname(),"未设置昵称"));
    }

//    @Override
//    public void onPause() {
//        super.onPause();
//        userBean= UserDataUtil.getUserData(getContext());
//        x.image().bind(iv_head,Constants.IMAGE_HOST+userBean.getHead_pic() , Constants.IMAGEOPTIONS);
//        tv_name.setText(TextUtil.getText(userBean.getNickname(),"未设置昵称"));
//    }



    @Override
    protected void doClick(int id) {
        super.doClick(id);
        switch (id){
            //下面三个跳转个人信息修改
            case R.id.tv_tint:
                openActivity(ActivityUserChange.class,null);
                break;
            case R.id.tv_name:
                openActivity(ActivityUserChange.class,null);
                break;
            case R.id.iv_head:
                openActivity(ActivityUserChange.class,null);
                break;

        }
    }

    @Override
    protected void initListener() {
        super.initListener();
        tv_tint.setOnClickListener(this);
        tv_name.setOnClickListener(this);
        iv_head.setOnClickListener(this);
    }


}
